package com.nbsaas.boot.project.rest.convert;

import com.nbsaas.boot.project.api.domain.simple.ProjectSimple;
import com.nbsaas.boot.project.data.entity.Project;
import com.nbsaas.boot.rest.api.Converter;

/**
 * 项目-列表对象转换器
 */

public class ProjectSimpleConvert implements Converter<ProjectSimple, Project> {


    @Override
    public ProjectSimple convert(Project source) {
        ProjectSimple result = new ProjectSimple();


        try {
            if (source.getCreator() != null) {
                result.setCreator(source.getCreator().getId());
            }
        } catch (Exception ignored) {
        }

        result.setAddress(source.getAddress());
        result.setColor(source.getColor());
        result.setLng(source.getLng());

        try {
            if (source.getCatalog() != null) {
                result.setCatalog(source.getCatalog().getId());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getCreator() != null) {
                result.setCreatorName(source.getCreator().getName());
            }
        } catch (Exception ignored) {
        }

        result.setBackMoney(source.getBackMoney());
        result.setAddDate(source.getAddDate());
        if (source.getProjectState() != null) {
            result.setProjectStateName(String.valueOf(source.getProjectState()));
        }
        result.setProjectState(source.getProjectState());

        try {
            if (source.getCatalog() != null) {
                result.setCatalogName(source.getCatalog().getName());
            }
        } catch (Exception ignored) {
        }

        result.setBeginDate(source.getBeginDate());
        result.setUsedTime(source.getUsedTime());

        try {
            if (source.getCharger() != null) {
                result.setCharger(source.getCharger().getId());
            }
        } catch (Exception ignored) {
        }

        result.setMoney(source.getMoney());
        result.setTotalNum(source.getTotalNum());
        result.setName(source.getName());
        if (source.getStoreState() != null) {
            result.setStoreStateName(String.valueOf(source.getStoreState()));
        }
        result.setStoreState(source.getStoreState());
        result.setId(source.getId());
        result.setDeadline(source.getDeadline());
        result.setLat(source.getLat());
        result.setLastDate(source.getLastDate());


        return result;
    }

}